package com.android.base.ui.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.example.lib_base.R;
import com.example.lib_base.databinding.LibBaseDialogVipOpenBinding;


/**
 * Created by Administrator on 2018\2\25 0025.
 */
public class DialogVipOpen extends AlertDialog {

    private Context mContext;
    private OnClickLister clickLister;
    private int resourcesId;
    private String btnText;
    private LibBaseDialogVipOpenBinding openBinding;

    public DialogVipOpen(Context context, OnClickLister listener, int resourcesId,String btnText) {
        super(context, R.style.dialog_loading);
        this.clickLister = listener;
        this.mContext = context;
        this.resourcesId = resourcesId;
        this.btnText = btnText;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        openBinding = LibBaseDialogVipOpenBinding.inflate(getLayoutInflater());
        setContentView(openBinding.getRoot());
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        init();
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
    }

    private void init() {
        openBinding.imgVipopen.setImageResource(resourcesId);
        openBinding.btnStart.setText(btnText);
        openBinding.btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickLister != null) {
                    clickLister.onStart(DialogVipOpen.this);
                }
            }
        });

        openBinding.imgClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(clickLister != null){
                    clickLister.onClose(DialogVipOpen.this);
                }
            }
        });
    }

    public interface OnClickLister {
        void onStart(Dialog dialog);
        void onClose(Dialog dialog);
    }
}